{% load static %}

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- layui样式 -->
    <link rel="stylesheet" href="{% static 'layui/css/layui.css' %}">
    <title>Document</title>
    <style>
        #code {
            width: calc(100% - 200px);
            float: left;
            margin-right: 8px;
        }

        .layui-col-space15 {
            margin: 0px;
        }

        .foot {
            height: 49px !important;
            line-height: 49px;
            text-align: right;
            background-color: #f5f5f5;
            border-top: 1px #e5e5e5 solid;
        }

        .foot button {
            width: 62px;
            height: 28px;
            line-height: 28px;
            margin-left: 2px;
            margin-right: 15px;
        }

        .foot .close:hover {
            border-color: #1E9FFF;
        }
    </style>
</head>

<body style="background-color: #ffffff">
<form class="layui-form" action="">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12" style="padding-bottom: 0;">
            <div class="layui-card">
                <div class="layui-card-body" pad15="">
                    <div class="layui-form" lay-filter="">
                        <!--容量--->
                        <div class="layui-form-item">
                            <label class="layui-form-label">容量</label>
                            <div class="layui-input-inline">
                                <input type="input" name="capacity" lay-verify="required" lay-vertype="tips"
                                       class="layui-input">
                            </div>
                        </div>

                        <!--价格-->
                        <div class="layui-form-item">
                            <label class="layui-form-label">价格</label>
                            <div class="layui-input-inline">
                                <input type="input" name="price" lay-verify="required" lay-verify="pass"
                                       lay-vertype="tips" autocomplete="off" id="LAY_password" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">6到16个字符</div>
                        </div>


                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="foot">
        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit=""
                lay-filter="setmypass">确定
        </button>
        <button type="button" class="layui-btn layui-btn-primary layui-btn-sm close" lay-filter="close">取消</button>
    </div>
</form>
<!-- layui JS -->
<script src="{% static 'layui/layui.js' %}"></script>
<script>

    layui.use(['form', 'jquery', 'layer'], function () {
        var form = layui.form;
        var $ = layui.jquery;
        var layer = layui.layer;


        //提交
        form.on('submit(setmypass)', function (data) {
            //获取表中参数
            let capacity = $('input[name="capacity"]').val();
            let price = $('input[name="price"]').val();
            console.log(capacity);
            console.log(price);

            //parent.layer.alert(JSON.stringify(data.field));
            //关闭当前弹出层
            let index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);

            $.ajax({
                url: "{% url 'hotel:room_manage' %}",
                type: 'post',
                data: {
                    code: 100, //增加操作
                    capacity: capacity,
                    price: price,
                    csrfmiddlewaretoken: '{{ csrf_token }}'
                },
                success: function (data) {
                    console.log(data.status);

                    //父页面刷新
                    parent.location.reload();
                }
            });
        });

        $('.close').click(function () {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
            return false;
        })


    });
</script>

</body>

</html>